import java.util.*;


public class Example03 {
    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Map<String, Integer> flowers = new HashMap<>();
        List<String> flowerNames = new ArrayList<>();
        int minScore = Integer.MAX_VALUE;
        String eliminatedFlower = "";

        for (int i = 0; i < n; i++) {
            String name = scanner.next();
            int score = scanner.nextInt();

            // 如果花的名字是第一次出现，添加到列表中
            if (!flowers.containsKey(name)) {
                flowerNames.add(name);
            }

            // 更新或初始化分数
            flowers.put(name, flowers.getOrDefault(name, 1000) + score);
            System.out.println(flowers);
            System.out.println(flowers.get(name));

            // 检查并更新最小分数
            if (flowers.get(name) < minScore) {
                minScore = flowers.get(name);
                eliminatedFlower = name;
            }
        }

        // 如果有多个花的分数相同，需要找到最先达到这个分数的花
        for (String name : flowerNames) {
            if (flowers.get(name) == minScore && flowers.get(name) < flowers.get(eliminatedFlower)) {
                eliminatedFlower = name;
            }
        }

        System.out.println(eliminatedFlower + " " + flowers.get(eliminatedFlower));
        long end=System.currentTimeMillis();
        System.out.println("程序运行了"+(end-start)+"秒");

    }
}
